package com.sooncode.project.focusservice.controller;

import com.sooncode.project.core.finder.Page;
import com.sooncode.project.focusservice._.base.Utils;
import com.sooncode.project.focusservice.model.Channel;
import com.sooncode.project.focusservice.model.Member;
import com.sooncode.project.focusservice.model.MemberStatus;
import com.sooncode.project.focusservice.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("member")
public class MemberController {
    @Autowired
    private MemberService service;

    @PostMapping("member")
    public boolean add(@RequestParam Map map){
        return service.add(map);
    }
    @PutMapping("member")
    public boolean modify(@RequestParam String id,@RequestParam Map map){
        return service.modify(id,map);
    }
    @DeleteMapping("member")
    public boolean delete(@RequestParam String[] ids){
        for(String id:ids){
            service.delete(id);
        }
        return true;
    }
    @GetMapping("members")
    public Page<Member> getPageList(@RequestParam int pageSize, @RequestParam int pageIndex, @RequestParam Map map){
        map.remove("pageSize");
        map.remove("pageIndex");
        Utils.mapValueTrim(map);
        return service.getPageList(pageSize,pageIndex-1,map);
    }
    // 会员状态与渠道
    @PostMapping("channel")
    public boolean addChannel(@RequestParam Map map){
        return service.addChannel(map);
    }
    @PutMapping("channel")
    public boolean modifyChannel(@RequestParam String id,@RequestParam Map map){
        return service.modifyChannel(id,map);
    }
    @DeleteMapping("channel")
    public boolean deleteChannel(@RequestParam String[] ids){
        for(String id:ids){
            service.deleteChannel(id);
        }
        return true;
    }
    @GetMapping("channels")
    public List<Channel> getChannelList(){
        return service.getChannelList();
    }
    @PostMapping("status")
    public boolean addStatus(@RequestParam Map map){
        return service.addMemberStatus(map);
    }
    @PutMapping("status")
    public boolean modifyStatus(@RequestParam String id,@RequestParam Map map){
        return service.modifyMemberStatus(id,map);
    }
    @DeleteMapping("status")
    public boolean deleteStatus(@RequestParam String[] ids){
        for(String id:ids){
            service.deleteMemberStatus(id);
        }
        return true;
    }
    @GetMapping("statuses")
    public List<MemberStatus> getStatusList(){
        return service.getMemberStatusList();
    }
    @PostMapping("importMember")
    public boolean importMember(@RequestParam MultipartFile[] files,@RequestParam String orgId){
        return service.importMembers(files,orgId);
    }
}
